/**
 * Created by guosc on 2016/11/4 0004.
 */
define([
    'require',
    'angular',
    'underscore'
], function () {
    return  function ($scope,$routeParams, Resource,GillionMsg,$rootScope,RuleSerivce) {
        $scope.packageId=$routeParams.packageId;
        Resource("/grule-manager/rulePackage/:id").get({
            id:$scope.packageId
        },function(resp){
            $scope.rulePackage=resp;
            if($scope.rulePackage.packageStatus==2){
                $scope.disabledPackage=true;
            }else{
                $scope.disabledPackage=false;
            }
        });

        var rulePackage=Resource("/grule-manager/rulePackage/updateRulePackage");

        $scope.reset=function(){
            Resource("/grule-manager/rulePackage/:id").get({
                id:$scope.packageId
            },function(resp){
                $scope.rulePackage=resp;
                if($scope.rulePackage.packageStatus==2){
                    $scope.disabledPackage=true;
                }else{
                    $scope.disabledPackage=false;
                }
            });
        }

        $scope.save=function(){
            angular.element('form[name="RulePackageForm"]').scope().RulePackageForm.verify().then(function(){
                $scope.rulePackage.conditions = null;
                rulePackage.update($scope.rulePackage,function(resp){
                    if(resp.success){
                        if($scope.rulePackage.packageStatus==2){
                            $scope.disabledPackage=true;
                        }else{
                            $scope.disabledPackage=false;
                        }
                        GillionMsg.alert("提示","保存成功！",function(){
                            RuleSerivce.setCurrentPackage($scope.rulePackage);
                            angular.element(document).trigger('refresh.menu');
                        });
                    }
                })
            })

        };
    }
});


